<?php
/*
 * Copyright 2010 Johannes M. Schmitt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

class closureCompileTask extends sfBaseTask
{
  protected function configure()
  {
    // // add your own arguments here
//     $this->addArguments(array(
//       new sfCommandArgument('configName', sfCommandArgument::REQUIRED, 'The configuration to compile.'),
//     ));

    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
      // add your own options here
    ));

    $this->namespace        = 'closure';
    $this->name             = 'compile';
    $this->briefDescription = '';
    $this->detailedDescription = <<<EOF
The [closure:compile|INFO] task does things.
Call it with:

  [php symfony closure:compile|INFO]
EOF;
  }

  protected function execute($arguments = array(), $options = array())
  {
  	$configuration = new GoogleClosureCompilerConfiguration(
  	  sfConfig::get('sf_web_dir').'/js/compiled/deps.js',
  	  'your.entry.point.class'  	  
  	);
  	
    $compiler = $configuration->createCompilerInstance();
   	
    
    $compiler = new GoogleClosureCompiler($files,
    								GoogleClosureCompiler::C_LEVEL_ADVANCED_OPTIMIZATIONS);
   	$compiler->setCommandLineFlag('process_closure_primitives', true);
   	$compiler->setCommandLineFlag('output_wrapper', '(function(){%output%})();');
   	$compiler->setCommandLineFlag('debug', false);
//   	$compiler->setStrictestDebugging();
//   	$compiler->setCommandLineFlag('warning_level', GoogleClosureCompiler::WARNING_LEVEL_VERBOSE);
//   	$compiler->setCommandLineFlag('compute_phase_ordering', 'true');
    $compiler->execute();
    
    // TODO: Process the compiler output here
  }
}
